<template>
    <div class="main">
        <el-card class="box-card">
            <Form :formobj="formobj" :formdata="formData" ref="form" :formrules="formrules"></Form>
            <div style="padding-left:100px">
                <el-button type="primary" @click="submit" >确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-card>
    </div>
</template>
<script>
import Form from "@/components/form.vue"
import { contentApiAdd, columnqueryAll, contentApiedit,contentApiqueryOne } from "@/api/webpage";
import { validateNum } from "@/utils/validator";
import { data } from "jquery";
export default {
    name: "zdgkdetails",
    components: {
        Form
    },
    data() {
        return {
            formData: {
                id:'',
                olumnId:'',
                title:'',
                content:'',
            },
            formobj: [
                { label: "标题", key: "title", type: "input" },
                { label: "内容", key: "content", type: "editor" }
            ],
            formrules: {
                title: [
                    { required: true, message: "请输入标题", trigger: "blur" },
                ],
                content: [
                    { required: true, message: "请输入正文", trigger: "change" },
                ],
            },
        }
    },
    created() {
        this.getdata('C0A8B1507E0441F28FA9448DF52AC6DC')
    },
    methods: {
        getdata(id){
            contentApiqueryOne({id:id}).then(res=>{
                if(res.code == 0){
                    this.formData = {
                        id:res.data.id,
                        columnId:res.data.columnId,
                        title:res.data.title,
                        content:res.data.content
                    }
     
                }
            })
        },
        submit(){
       this.$refs.form.getData().then(res=>{
           contentApiedit(res).then((response) => {
              if (response.data == 1) {
                this.$message.success("成功");
                this.$router.go(-1)
              } else {
                this.$message.error("失败");
              }
            })
            .catch((err) => {
              console.log(err);
            });
        })
        },
        
        cancel(){
            this.$router.go(-1)
        },
    }
}
</script>
<style scoped>
@import "~@/assets/css/adminstyle.css";
</style>